<?php
declare(strict_types=1);

namespace App\Common\Modular\System\Traits\Configure\Traits;

use Core\Package\ElementPlus\FormCreate\FormItem;
use Zms\Exception\FormException;

trait SystemForm
{
    /**
     * 获取系统配置
     * @param $configure
     * @return array
     * @throws FormException
     */
    public function getSystemFormRule($configure): array
    {
        return [
            FormItem::Input('company', '公司名称', $configure['company'] ?? '')->placeholder('公司名称')->maxlength(10)->required('请设置公司名称'),
            FormItem::Radio('is_access_log', '写访问日志', $configure['is_access_log'] ?? '0')->options([['value' => '1', 'label' => '写访问日志'], ['value' => '0', 'label' => '不写访问日志']])->required('请选择是否写访问日志')->hint('记录HTTP访问记录'),
            FormItem::Radio('is_check_data', '数据安全检测', $configure['is_check_data'] ?? '0')->options([['value' => '1', 'label' => '开启'], ['value' => '0', 'label' => '关闭']])->required('请选择是否进行安全检测')->hint('对提交的数据进行安全检测,抵御常见sql注入,xss攻击')
                ->control([
                    [
                        'value' => '1',
                        'rule' => [
                            FormItem::Checkbox('check_data_types', '验证数据类型', $configure['check_data_types'] ?? ['post', 'get', 'cookie'])
                                ->options([
                                    ['value' => 'post', 'label' => 'POST'],
                                    ['value' => 'get', 'label' => 'GET'],
                                    ['value' => 'cookie', 'label' => 'COOKIE'],
                                ])
                                ->hint('不设置代表全部验证')
                        ]
                    ]
                ]),
            FormItem::Input('host', '站点域名', $configure['host'] ?? '')->hint('项目站点域名'),
            FormItem::Input('domain', '资源域名', $configure['domain'] ?? '')->hint('项目静态资源资源,上传文件域名'),
            FormItem::Radio('mourn', '哀悼模式', $configure['mourn'] ?? '0')->options([['value' => '0', 'label' => '关闭'], ['value' => '1', 'label' => '开启']])->info('开启后系统界面只显示黑白色彩'),
        ];
    }


    /**
     * 系统客服表单
     * @param $configure
     * @return array
     */
    public function getSystemCustomerFormRule($configure): array
    {
        return [
            FormItem::Switchs('chat_open', '在线客服', $configure['chat_open'] ?? '1')->inactiveText('关闭')->activeText('开启'),
            FormItem::Switchs('tel_open', '电话客服', $configure['tel_open'] ?? '1')->inactiveText('关闭')->activeText('开启'),
            FormItem::Input('service_date', '服务时间', $configure['service_date'] ?? '')->placeholder('客服服务时间')->maxlength(30)->required(),
            FormItem::Input('customer_tel', '客服电话', $configure['customer_tel'] ?? '')->placeholder('请输入客服电话')->maxlength(30)->required(),
        ];
    }
}